package com.yylending.las.lending.quota.initdata;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import com.yylending.las.Global;
import com.yylending.las.lending.quota.entity.OptionBean;
import com.yylending.las.lending.quota.idcard.IdCardModel;

import java.util.ArrayList;
import java.util.List;

import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

/**
 * Created by laixj on 2016/11/10.
 * Copyright © 2016 www.yyfax.com. All Rights Reserved.
 */
public class InitDataModel extends Model {

	public final static String TAG = IdCardModel.class.getSimpleName();

	public final static int METHOD_GET_OPTION = 0;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		switch (functionalCode) {
			case METHOD_GET_OPTION:
				return service.getOptionList(Global.LOGIN_TOKEN, new EmptyEntity());
		}
		return null;
	}

	@Override
	public void onNext(Object entity) {
		CLog.i(TAG, "onNext: " + entity.toString());
		BaseResultEntity result = cast(entity);
		switch (result.requestCode) {
			case METHOD_GET_OPTION:
				OptionsResult optionsResult = cast(entity);
				EventAgent.post(optionsResult);
				break;
		}
	}

	private interface Service {
		/**
		 * 获取选项卡接口
		 */
		@POST("server/params/getParams")
		Observable<OptionsResult> getOptionList(@Header("token") String token, @Body EmptyEntity params);
	}

	static class OptionsResult extends BaseResultEntity<Options> {
	}

	public static class LoanThreshold  {
		/**
		 * 最低可借款阈值
		 */
		public String loanLineAmount;
		/**
		 * 线上最高可借阈值
		 */
		public String highLoanLine;
		/**
		 * 最大借款阈值
		 */
		public String maxLoanAmount;
	}

	public static class Options {
		/**
		 * _id : 5934c299209d2dfb1b1d85a1
		 * workType : [{"itemNo":1,"itemName":"自雇"},{"itemNo":2,"itemName":"受薪"}]
		 * hasHouse : [{"itemNo":1,"itemName":"无"},{"itemNo":2,"itemName":"有"}]
		 * marriage : [{"itemNo":1,"itemName":"未婚"},{"itemNo":2,"itemName":"已婚"}]
		 * education : [{"itemNo":1,"itemName":"硕士及以上"},{"itemNo":2,"itemName":"本科"},{"itemNo":3,"itemName":"大专"},{"itemNo":4,"itemName":"高中/中专"},{"itemNo":5,"itemName":"初中及以下"}]
		 * living : [{"itemNo":1,"itemName":"自建"},{"itemNo":2,"itemName":"自购无贷款"},{"itemNo":3,"itemName":"自购有贷款"},{"itemNo":4,"itemName":"租用"},{"itemNo":5,"itemName":"亲戚住房"},{"itemNo":6,"itemName":"单位住房"},{"itemNo":7,"itemName":"其他"}]
		 */

		public List<OptionBean> marriage = new ArrayList<>();
		public List<OptionBean> education = new ArrayList<>();
		public List<OptionBean> living = new ArrayList<>();
		public List<OptionBean> relation = new ArrayList<>();

		public LoanThreshold loanLine;

		@Override
		public String toString() {
			return "Options{" +
					"marriage=" + marriage +
					", education=" + education +
					", living=" + living +
					", kinship=" + relation +
					'}';
		}
	}

	/**
	 * 获取选项卡
	 */
	public static class GetOptionList {
		List<String> types;

		public GetOptionList(List<String> types) {
			this.types = types;
		}
	}
}
